package com.blb.routing;

import com.blb.util.MQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;

/**
 路由模式的生产者，发布消息会有特定的Key，消息会被绑定特定Key的消费者获取
 */
public class RouteProductor {

    public static void main(String[] args) throws IOException, InterruptedException {
        Connection connection = MQUtils.getConnection();
        Channel channel = connection.createChannel();
        //声明交换机类型为direct
        channel.exchangeDeclare(MQUtils.EXCHANGE_NAME2,"direct");
        //绑定队列1到交换机，指定了Key为error
        channel.queueBind(MQUtils.QUEUE_NAME,MQUtils.EXCHANGE_NAME2,"error");
        //绑定队列2到交换机，指定了Key为debug
        channel.queueBind(MQUtils.QUEUE_NAME2,MQUtils.EXCHANGE_NAME2,"debug");
        //error是一个指定的Key
        channel.basicPublish(MQUtils.EXCHANGE_NAME2,"error",null,"Test Error".getBytes());
        channel.basicPublish(MQUtils.EXCHANGE_NAME2,"debug",null,"Test Debug".getBytes());
        channel.close();
        connection.close();
    }
}
